using NL.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using static NL.UI.UI;

namespace NL.AdreesableAsset
{
    public static class AAExtend 
    {
        //public static AsyncOperationHandle<T> CreateWindowAA<T>(this UI.UI uiroot,string name) where T:Window
        //{
        //    var oper=  Addressables.LoadAssetAsync<T>(name);
        //    return oper;
        //}

        public static T CreateWindowAA<T>(this UI.UI uiroot, string name,Transform root=null) where T : Window
        {
            var w = AA.LoadAndWait<T>(name);

            if (w != null)
            {
                return    uiroot.Create_Window(w, root);
            }
            return null;
        }

        public static T CreateWindowAA<T>(this UI.UI uiroot, string name,  UILayer layer) where T : Window
        {
            var w = AA.LoadAndWait<T>(name);

            if (w != null)
            {
                return uiroot.Create_Window(w, layer);
            }
            return null;
        }
        public static T CreateWindowAA<T>(this UI.UI uiroot, string name, UILayerRoot layeroot) where T : Window
        {
            var w = AA.LoadAndWait<T>(name);

            if (w != null)
            {
                return uiroot.Create_Window(w, layeroot);
            }
            return null;
        }
    }
}

